import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import static org.apache.spark.sql.functions.col;

public class SparkSQL {
    public static void main(String[] args) {
        SparkSession spark = SparkSession
                .builder()
                .appName("Java Spark SQL basic example")
                .master("local[*]")
                .config("spark.some.config.option", "some-value")
                .getOrCreate();

        Dataset<Row> df=spark.read().json("BaseDemo/sparksql.json");
        df.show();

        df.printSchema();

        df.select("name").show();

        df.select(col("name"),col("age").plus(1)).show();

        df.filter(col("age").gt(21)).show();

        df.groupBy("age").count().show();
    }
}
